package logic

import (
	"context"
	"houses_srv/models"

	"houses_srv/houses"
	"houses_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowUserLogic {
	return &ShowUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowUserLogic) ShowUser(in *houses.ShowUserRequest) (*houses.ShowUserResponse, error) {
	// todo: add your logic here and delete this line

	var u models.User
	u.ID = uint(in.UserId)
	err := u.ShowUser()
	if err != nil {
		return nil, err
	}

	var h models.House
	h.UserId = int(in.UserId)
	err = h.ShowHouseByUserId()
	if err != nil {
		return nil, err
	}

	return &houses.ShowUserResponse{
		Mobile:    u.Mobile,
		Title:     h.Title,
		Image:     h.Image,
		Price:     int64(h.Price),
		Fool:      float32(h.Fool),
		HouseType: h.HouseType,
	}, nil
}
